﻿
ValControl = function(ControlObj, RexExpression, initialValue) {
    if (ControlObj != null) {
        var patt = new RegExp(RexExpression);
        if (!patt.test(ControlObj.value)) {
            ControlObj.value = initialValue;
            return false;
        }
        return true;
    }
}


ValObjValue = function(objValue, RexExpression) {
    if (objValue != null) {
        var patt = new RegExp(RexExpression);
        if (!patt.test(objValue)) {            
            return false;
        }
        return true;
    }
}

function setControlValue(obj) {
    document.getElementById('control1').value = obj;
    return true;
}

function CommentsDisplay(obj, controlID, flag) {
    var pos = getAbsolutePosition(obj);
    var c = document.getElementById(controlID);
    if (flag == 0) {
        c.style.visibility = 'hidden';
    }
    else if (flag == 1) {
        c.style.top = (pos.y - 20) + "px";
        c.style.left = (pos.x + 30) + "px";
        c.style.visibility = 'visible';
    }
}


function getAbsolutePosition(obj) {
    position = new Object();
    position.x = 0;
    position.y = 0;
    var tempobj = obj;
    while (tempobj != null && tempobj != document.body) {
        position.x += tempobj.offsetLeft + tempobj.clientLeft;
        position.y += tempobj.offsetTop + tempobj.clientTop;
        tempobj = tempobj.offsetParent
    }
    return position;
}

SetLoadPop = function(txt) {
    var loadDiv = $("#loading");
    loadDiv.show();
    loadDiv.fadeTo("slow", 0.5);

    var divHeight = document.body.clientHeight;

    if (divHeight < window.innerHeight)
        divHeight = window.innerHeight;

    loadDiv.width(document.body.clientWidth);    
    loadDiv.height(divHeight);


    var scrollTop = $(window).scrollTop();
    var loadPop = $("#loadingPop");
    loadPop.css({ left: ($(window).width() - 350) / 2 + "px" });
    loadPop.css({ top: (scrollTop + 200) + "px" });

    $("#loadingTxt").html(txt);
}

ShowPop = function(popWidth, popHeight, MarginTop, PopWindowID) {

    var bk = $("#PopupBackGroud");
    var divHeight = document.body.clientHeight;

    if (divHeight < window.innerHeight)
        divHeight = window.innerHeight;
        
    bk.width(document.body.clientWidth);
    bk.height(divHeight);
    bk.show();
    bk.fadeTo("slow", 0.5);
    
    var PopWindow = $("#" + PopWindowID);

    PopWindow.show();
    PopWindow.fadeTo("slow", 1);
    PopWindow.width(popWidth + "px");
    $(".PopBody").height(popHeight + "px");
    PopWindow.css({ left: (($(window).width() - popWidth) / 2) + 10 + "px" });
    PopWindow.css({ top: MarginTop + "px" });
    PopWindow.focus();

}

ShowTipPop = function(tipText) {
$("#SavePopTxt").html(tipText);
$("#btnNosave").hide();
$("#btnsave").hide();

var scrollTop = $(window).scrollTop();
//var left = ($(window).width() - 350) / 2;
var top = scrollTop + 200;

ShowPop('617', '100', top, 'SavePop');
}

ClosePop = function(PopWindowID) {
    var bk = $("#PopupBackGroud");
    bk.fadeTo("slow", 0);
    bk.hide("slow");

    var PopWindow = $("#" + PopWindowID);        
    PopWindow.fadeTo("slow", 0);
    PopWindow.hide("slow");


}

function HideShowDiv(divObjID, triggerObj, ContentTxt) {
    //var triggerObj = document.getElementById(triggerObjid);

    if (triggerObj.className == "HideBtn") {
        $("#" + divObjID).slideUp(80);
        triggerObj.title = "Show " + ContentTxt;
        triggerObj.className = "ShowBtn";
    }
    else {
        $("#" + divObjID).slideDown(80);
        triggerObj.title = "Hide " + ContentTxt;        
        triggerObj.className = "HideBtn";
    }
}

function CheckExplain(radioObj, controlNo) {
    var ctl00_Hd_r3 = document.all ? document.all["ctl00_Hd_r" + controlNo] : document.getElementById("ctl00_Hd_r" + controlNo);

    if (radioObj.value == "Y")
        ctl00_Hd_r3.validationGroup = "vv";
    else
        ctl00_Hd_r3.validationGroup = "oo";
}

function CheckFile() {
    var upload = document.getElementById("ctl00_Hd_FileUpload1");
    var filename = upload.value;

    var ext = filename.substr(filename.length - 4, 4).toUpperCase();

    if (!(ext == ".JPG" || ext == ".PDF" || ext == ".JPEG")) {
        alert("JPG or PDF document only.");
        upload.value = "";
        return false;
    }

    return true;
}

Request = {
    QueryString: function(item) {
        var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i"));
        return svalue ? svalue[1] : svalue;
    }
}

function CheckCPLocations() {
    __doPostBack('ctl00$Hd$Lkbtn', '');
}